<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:f="livcos.org/ns/xslt/function" xmlns="http://www.w3.org/1999/xhtml" xmlns:doc="livcos.org/ns/doc" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:pm="livcos.org/ns/pm" version="2.0" exclude-result-prefixes="doc pm f xs">
	
	<xsl:import href="../../../style/base.xsl"/>
  
	<xsl:param name="ref" select="'../../data/pm/Roadmap'"/>

	<xsl:param name="incl" select="-1" as="xs:integer"/>
  <xsl:param name="excl" select="-1" as="xs:integer"/>
  
  <xsl:function name="f:sort">
    <xsl:param name="in"/>
    <xsl:perform-sort select="$in">
      <xsl:sort select="."/>
    </xsl:perform-sort>
  </xsl:function>

  <xsl:function name="f:countMonths" as="xs:integer">
    <xsl:param name="date"/>
    <xsl:sequence select="month-from-date($date) + (year-from-date($date) * 12)"/>
  </xsl:function>

  <xsl:variable name="root" select="document($ref)/*"/>
  <xsl:variable name="apps" as="node()*">
    <xsl:choose>
      <xsl:when test="$incl &gt; 0">
        <xsl:sequence select="$root//pm:application[position() = $incl]"/>
      </xsl:when>
      <xsl:when test="$excl &gt; 0">
        <xsl:sequence select="$root//pm:application[position() != $excl]"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:sequence select="$root//pm:application"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  <xsl:variable name="first" select="xs:date(f:sort($apps/pm:release/@startDate)[1])"/>
	<xsl:variable name="last" select="xs:date(f:sort($apps/pm:release/@releaseDate)[last()])"/>
  <xsl:variable name="months" as="xs:date*">
    <xsl:for-each select="0 to (f:countMonths($last) - f:countMonths($first))">
      <xsl:sequence select="$first + (xs:yearMonthDuration('P1M') * xs:double(.))"/>
    </xsl:for-each>
  </xsl:variable>
  <xsl:variable name="days" select="days-from-duration($last - $first)"/>

	<xsl:template match="/">
	  <xsl:apply-templates select="$root"/>
	</xsl:template>
	
  <xsl:template match="/*">
  	<div class="timeline">
    <table cellspacing="0">
      <thead>
        <tr>
          <td>&#160;</td>
          <td>
          	<div style="width: {ceiling(count($months) * 30.5)}px">
            <xsl:for-each select="$months">
              <xsl:variable name="d" select="days-from-duration((. + xs:yearMonthDuration('P1M')) - .)"/>
              <div style="width:{$d}px; float:left;">
                <div>
                  <xsl:if test="(position() = 1) or (month-from-date(.) = 1)">
                    <xsl:attribute name="class">month</xsl:attribute>
                    <xsl:value-of select="format-number(year-from-date(.), '0000')"/>
                  </xsl:if>&#160;
                </div>
                <div class="month">
                  <xsl:value-of select="format-number(month-from-date(.), '00')"/>
                </div>
              </div>
            </xsl:for-each>
          		</div>
          </td>
        </tr>
      </thead>
      <xsl:apply-templates select="$apps"/>
    </table>
  	</div>
  </xsl:template>
  
  <xsl:template match="pm:application">
    <tbody id="{f:object-id(.)}#{@id}~1">
      <tr>
        <td>
          <xsl:value-of select="doc:title"/>
        </td>
        <td>
          &#160;
        </td>
      </tr>
      <xsl:apply-templates select="pm:release"/>
    </tbody>
  </xsl:template>
  
  <xsl:template match="pm:release">
    <tr id="{@id}~1">
			<td>
				<xsl:text>&#160;&#160;</xsl:text>
				<a href="#{@id}">
					<xsl:value-of select="@num"/>
					<xsl:if test="@label">
						<xsl:text> </xsl:text>
						<xsl:value-of select="@label"/>
					</xsl:if>
				</a>
			</td>
			<td>
				<xsl:choose>
					<xsl:when test="@releaseDate">
						<xsl:variable name="s" select="days-from-duration(xs:date(@startDate) - $first) + day-from-date($first)"/>
						<xsl:variable name="d" select="days-from-duration(xs:date(@releaseDate) - xs:date(@startDate))"/>
						<xsl:choose>
							<xsl:when test="$d &gt; 70">
								<div class="bar" style="margin-left:{$s}px; width:{$d}px;">
									<div class="end">
										<xsl:value-of select="@releaseDate"/>
									</div>
								</div>
							</xsl:when>
							<xsl:otherwise>
								<div style="margin-left:{$s}px;">
									<div class="bar" style="width:{$d}px; margin-right: 1px;">&#160;</div>
									<div class="endOut">
										<xsl:value-of select="@releaseDate"/>
									</div>
								</div>
							</xsl:otherwise>
						</xsl:choose>
					</xsl:when>
					<xsl:otherwise>
						<xsl:text>&#160;</xsl:text>
					</xsl:otherwise>
				</xsl:choose>
			</td>
    </tr>
  </xsl:template>
  
</xsl:stylesheet>
